package com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider;

import com.evenmo.hrms.pojo.Notice;
import org.apache.ibatis.jdbc.SQL;

public class NoticeDynaSqlProvider {
    public String selectByParams(Notice notice) {
        return new SQL() {
            {

                SELECT("*");
                FROM("notice");
                if (notice.getTitle() != null) {
                    WHERE("title like concat('%',#{title},'%')");
                }
                if (notice.getContent() != null) {
                    WHERE("content like concat('%',#{content},'%')");
                }

                if (notice.getUserId() != null) {
                    WHERE("userId=#{userId}");
                }
                if (notice.getCreateTime() != null) {
                    WHERE("createTime=#{createTime}");
                }
            }
        }.toString();
    }

    public String insertByParams(Notice notice) {
        return new SQL() {
            {
                INSERT_INTO("notice");
                if (notice.getTitle() != null) {
                    VALUES("title", "#{title}");
                }
                if (notice.getContent() != null) {
                    VALUES("content", "#{content}");
                }
                if (notice.getUserId() != null) {
                    VALUES("userId", "#{userId}");
                }
                if (notice.getCreateTime() != null) {
                    VALUES("createTime", "#{craeteTime}");
                }


            }
        }.toString();
    }

    public String updateByParams(Notice notice) {
        return new SQL() {
            {
                UPDATE("notice");
                if (notice.getCreateTime() != null) {
                    SET("createTime=#{createTime}");
                }
                if (notice.getContent() != null) {
                    SET("content=#{content}");
                }
                if (notice.getTitle() != null) {
                    SET("title=#{title}");
                }
                if (notice.getUserId() != null) {
                    SET("userId=#{userId}");
                }

                WHERE("id=#{id}");


            }
        }.toString();
    }
}
